 package com.zz.service;


import java.util.Optional;

import javax.annotation.Resource;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import com.zz.entity.Product;
import com.zz.entity.Ware;
import com.zz.repository.ProductRepository;
import com.zz.repository.WareRepository;

@Service
public class ProductService {
	@Resource
	ProductRepository productRepository;
	@Resource
	WareRepository wareRepository;
	//显示所有商品信息并进行分页
	public Page<Object[]> getall(String startpage,String limit){
		Pageable pageable=PageRequest.of(Integer.parseInt(startpage), Integer.parseInt(limit));
		return  productRepository.getall(pageable);
	}
	//根据id修改商品信息
	public Integer updatepdt(String type,String location,Integer num,String wid,String id){
		return productRepository.updatepdt(type, location, num, wid, id);
	}
	//根据id删除商品
	public int deletepdt(String id){
		return productRepository.deletepdt(id);
	}
	//根据名字查询商品信息
	 //分页排序
	public Page<Object[]> findByName(String name,String startpage,String limit){
	Pageable pageable = PageRequest.of(Integer.parseInt(startpage), Integer.parseInt(limit));
	return productRepository.findByName(name, pageable);
	}
	//查询仓库信息ByName
	public Ware findwareByname(String name) {
		 return wareRepository.findByName(name);
	}
	//查询商品信息ById
	public Optional<Product> findproductById(String id) {
		return productRepository.findById(id);
	}


}
